package com.chuan.thinkingjava.lock;

import java.util.Vector;
import java.util.concurrent.locks.ReentrantLock;

public class AQSTest {

    static ReentrantLock lock = new ReentrantLock(true);

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(() -> new Runnable() {
                @Override
                public void run() {
                    lock.lock();
                    Vector<String> v = new Vector<>();
                    v.add("");
                    System.out.println("Thread is " + Thread.currentThread().getName());
                    try {
                        Thread.sleep(2000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        lock.unlock();
                    }
                }
            });
            thread.start();
        }
    }
}
